﻿using System;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace ContractManager.Common.Service
{
    /// <summary>
    /// Dialog service. 
    /// </summary>
    /// <remarks>
    /// Golovkov Alex, 30.10.2010. 
    /// </remarks>
    public static class DialogService
    {
        #region Public Methods

        /// <summary>
        /// Gets an open file name. 
        /// </summary>
        /// <remarks>
        /// Golovkov Alex, 30.10.2010. 
        /// </remarks>
        /// <param name="filterString">
        /// The filter string. 
        /// </param>
        /// <returns>
        /// The open file name. 
        /// </returns>
        public static string GetOpenFileName(string filterString)
        {
            var openDialog = new OpenFileDialog { Filter = filterString };
            if (openDialog.ShowDialog() != DialogResult.OK)
            {
                return String.Empty;
            }

            if (String.IsNullOrEmpty(openDialog.FileName))
            {
                XtraMessageBox.Show("Файл указан неверно");
                return String.Empty;
            }

            return openDialog.FileName;
        }

        /// <summary>
        /// Gets a save file name. 
        /// </summary>
        /// <remarks>
        /// Golovkov Alex, 30.10.2010. 
        /// </remarks>
        /// <param name="filterString">
        /// The filter string. 
        /// </param>
        /// <returns>
        /// The save file name. 
        /// </returns>
        public static string GetSaveFileName(string filterString)
        {
            var openDialog = new SaveFileDialog { Filter = filterString };
            if (openDialog.ShowDialog() != DialogResult.OK)
            {
                return String.Empty;
            }

            if (String.IsNullOrEmpty(openDialog.FileName))
            {
                XtraMessageBox.Show("Файл указан неверно");
                return String.Empty;
            }

            return openDialog.FileName;
        }

        #endregion
    }
}
